﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace aspnet2.User
{
    public partial class UserProfile : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
        try
            {
            if (this.UserName.Text != null)
                {
                this.UserName.Text = null;
                }
            }
        catch (Exception ex)
            {

            this.ErrorInfo.Text = ex.Message;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            try

            {
            if (Membership.ValidateUser(this.UserName.Text, this.PWD.Text))
                {
                
                FormsAuthentication.SetAuthCookie(this.UserName.Text, false);
                if (Request["ReturnUrl"] == null)
                    Response.Redirect(FormsAuthentication.DefaultUrl);
                else Response.Redirect(Request["ReturnUrl"]);
              
                }
            else throw new Exception("validate failed");
                    
                  
            }
            catch (Exception ex) {
                this.ErrorInfo.Text = ex.Message;
            }
        }

        protected void Button3_Click(object sender, EventArgs e)
            {
            try
                {
                Response.Redirect("~/Register.aspx");
                }
            catch (Exception ex)
                {

                this.ErrorInfo.Text = ex.Message;
                }
            }

        protected void LinkButton1_Click(object sender, EventArgs e)
            {
            try
                {
                Response.Redirect("~/Register.aspx");
                }
            catch (Exception ex)
                {
                this.ErrorInfo.Text = ex.Message;
                }
            }
    }
}
